<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * date: 2021-09-07 20:25:16
 * @LastEditors: Sam
 * @LastEditTime: 2021-12-08 20:20:09
-->
{include file="common/public/header"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form padsome" action="">  
                   
                    <div class="layui-form-item" >
                        <div class="layui-form-label">优惠券类型</div>
                        <div class="layui-input-block">
                            <input type="radio"  name="type" {$info.type==0?'checked':''} lay-filter="type"  title="通用券"  checked value="0" />
                            <input type="radio"  name="type"  {$info.type==1?'checked':''}  lay-filter="type" title="品类券"  value="1" />
                            <input type="radio"  name="type"  {$info.type==2?'checked':''}  lay-filter="type"  title="商品券"  value="2" />
                        </div>
                    </div>
                    <div class="layui-form-item" >
                        <div class="layui-form-label">优惠券名称</div>
                        <div class="layui-input-block">
                            <input class="layui-input"  name="title"  lay-verify="required"  placeholder="请输入优惠券名称"  value="{$info.title}"/>
                        </div>
                    </div>
                    <div class="layui-form-item" >
                        <div class="layui-form-label">优惠券图片</div>
                        <div class="layui-input-block">
                            <input type="hidden" name="thumb" id="thumb" value='{$info.thumb}' />
                        </div>
                    </div>
                    <div class="layui-form-item type type1" style="{$info.type==1?'':'display:none'}">
                        <div class="layui-form-label">商品分类</div>
                        <div class="layui-input-block">
                            <select  name="category_id"  lay-search >
                                <option value="">请选择商品分类</option>
                                {volist name="cates" id='cate'} 
                                    <option value="{$cate.id}" {$info.category_id==$cate.id ?'selected' : ''}>{$cate.html}{$cate.cate_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item type type2" style="{$info.type==2?'':'display:none';}">
                        <div class="layui-form-label">商品选择</div>
                        <div class="layui-input-block">
                            <div id='product_id'></div>
                        </div>
                    </div>
                    <div class="layui-form-item" >
                        <div class="layui-inline">
                            <div class="layui-form-label">优惠券面值</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input"  name="coupon_price"  placeholder="请输入优惠券面值"  type="number"  value="{$info.coupon_price}"/>
                                </div>
                            <div class="layui-form-label">最低消费</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input"  name="use_min_price"  placeholder="请输入优惠券最低消费"  type="number"  value="{$info.use_min_price}"/>
                                </div>
                        </div>
                    </div>
                     <div class="layui-form-item" >
                        <div class="layui-inline">
                            <div class="layui-form-label">有效期(天)</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input"  name="coupon_time"  placeholder="请输入优惠券有效期"  type="number"  value="{$info.coupon_time|default=1}"/>
                                </div>
                            <div class="layui-form-label">排序</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input"  name="sort"   type="number"  value="{$info.sort|default=1}"/>
                                </div>
                        </div>
                     </div>
    

                    <div class="layui-form-item" >
                        <div class="layui-form-label">状态</div>
                        <div class="layui-input-block">
                            <input type="radio"  name="status"  title="开启" {$info.status==1?'checked':''} value="1" />
                            <input type="radio"  name="status"  {$info.status==0?'checked':''}  title="关闭"  value="0" />
                        </div>
                    </div>                   
                    <div class="layui-form-item">
                        <div class="layui-input-block layui-layout-admin">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="">立即提交</button>
                                <button class="layui-btn layui-btn-primary" type="button" onclick="close_frame()">返回</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{include file="common/public/footer" /}
<script>
    layui.extend({
        xmSelect: 'xm-select'
    }).use(['index', 'form', 'layarea', 'laydate', 'xmSelect'], function(){
        var $       = layui.$;
        var form    = layui.form;
        // var xmSelect = layui.xmSelect;
        uploadInit('thumb', 'image', '');
        xmSelect.render({el: '#product_id', filterable: true,name:'product_id', data:{$goods_select|raw}, initValue: "{$info.product_id|raw}"});
        form.render();
        form.on('radio(type)',function(data){
            var type = data.value;
            $('.type').hide();
            $('.type'+type).show();
            form.render();
        });
        // 监听表单提交
        form.on('submit()', function(data){
            Post('', data.field, function(res) {
                if (res.code == 1) {
                    alert_success(res.msg, function() {
                        parent.layui.table.reload('table', {where: parent.where});
                        close_frame();
                    })
                } else {
                    alert_error(res.msg);
                }
            });
            return false;
        });

});
</script>\